<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/taglibs.jsp"%>
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<link href="${ctx}/resources/trend/semantic/dist/semantic.min.css"	rel="stylesheet" type="text/css" />
<link href="${ctx}/resources/trend/semantic/dist/components/modal.min.css" 	rel="stylesheet" type="text/css" />
<link href="${ctx}/resources/trend/semantic/dist/components/icon.min.css"	rel="stylesheet" type="text/css" />
<link href="${ctx}/resources/trend/apps.css" rel="stylesheet" type="text/css" />
<title>医趋势会员</title>
<style type="text/css">
	<%--.select {--%>
   	<%-- 	border: 1px solid #0099e9;--%>
   	<%-- 	background: url(${ctx}/resources/images/icon_changci.png) no-repeat right bottom;--%>
   	<%-- 	 height: 38px;--%>
	<%--    border: 1px solid #0099e9;--%>
	<%--    margin: 0px 10px 10px 0;--%>
	<%--}--%>
	
	li {
		list-style: none outside none; 
	    display: inline-block;
	    cursor: pointer;
	    margin: 0 10px 10px 0;
	    float: left;
	    border: 1px solid #e2e2e2;
	    overflow: hidden;
	    width: 158px;
	    height: 38px;
	    position: relative;
	}
	.code_tab{height: 30px;}
	.code_tab label{
		font-size: 13px;
		display: block;width: 60px;height: 30px;line-height: 30px;
		text-align: center;float: left;background:#c7c9cc;color: #fff;
	}
	.code_tab .active{background:#fa6c15;}
</style>
</head>
<body>
<%--	<%@include file="/views/modaldialog.jsp"%>--%>
	<div class="ui segment" id="n-title">
		<br>&nbsp; 医趋势会员全新升级&nbsp; <br>&nbsp; <br>&nbsp;
	</div>
	<div class="ui segments" id="n-body">
		<div class="ui segment" id="n-page">
			<div class="ui segment" id="n-content">
			<!-- <div class="ui header" style=" font-size: 1em; padding-bottom: 0.8em;font-weight: 300;"> 
				<input type="hidden" value="医疗创新人才趋势研讨会" id="bodydesc">
	    		<h3>医疗创新人才趋势研讨会</h3>
	    		主办：医趋势&医人才<br/><br/>
	    		地点：上海市黄浦区广东路500号<br/><span style="margin-left:3em;">世界贸易大厦5楼wework5J会议室</span><br/><br/>
	    		时间：2019年12月21日<br/>
			</div> -->
	<div class="pay-wrap">
		<section class="ui form">
			<div class="pay">
				<div class="field">
					<label><font color="red">*</font>姓名</label>
					<div class="ui input">
						<input type="text" id="name" name="name"  placeholder="">
					</div>
				</div>
				<div class="field">
					<label><font color="red">*</font>手机号码</label>
					<div class="ui input">
						<input type="text" id="phone" name="phone" placeholder="">
					</div>
				</div>
			 	<div class="field">
					<label><font color="red">*</font>您所在公司名称</label>
						<div class="ui input">
							<input  type="text" id="companyname" name="companyname"placeholder="">
						</div>
				</div>
				<div class="field">
					<label><font color="red">*</font>您目前担任的职位</label>
						<div class="ui input">
							<input  type="text" id="positionname" name="positionname"placeholder="">
						</div>
				</div>
				
				<!-- <div class="field">
					<div class="code_tab">
						<label class="active" data-type="recomCode">专属码</label>
						<label data-type="vipCode">VIP码</label>
					</div>
					<div class="ui input code_con recomCode">
						<input type="text" name="code" placeholder="请输入推荐码">
					</div>
					<div class="ui input code_con vipCode" style="display:none;">
						<input type="text" name="vipCode" placeholder="请输入VIP码">
					</div>
				</div> -->
				
<%--				<div class="field ticket_con">--%>
<%--					<label>票种</label> --%>
<%--						<div class="ui input">--%>
<%--							<input id="payType" type="hidden" value="en"/>--%>
<%--							<input id="goodsid" type="hidden" value="en001"/>--%>
<%--							<li class="ticket select" data-money="299" style="display: block;">--%>
<%--								<table width="130" border="0" cellspacing="0" cellpadding="0">--%>
<%--									<tbody>--%>
<%--										<tr>--%>
<%--											<td align="center" valign="middle">--%>
<%--												<span class="ticket_des">普通观众收费&nbsp;&nbsp;&nbsp;&nbsp;</span> --%>
<%--												<span class="ticket_money"><span>¥</span>299/人</span>--%>
<%--											</td>--%>
<%--										</tr>--%>
<%--									</tbody>--%>
<%--								</table>--%>
<%--							</li>--%>
<%--							--%>
<%--							<li class="ticket"  data-money="258" style="display: block;">--%>
<%--								<table width="130" border="0" cellspacing="0" cellpadding="0">--%>
<%--									<tbody>--%>
<%--										<tr>--%>
<%--											<td align="center" valign="middle">--%>
<%--												<span class="ticket_des">--%>
<%--													医趋势会员收费--%>
<%--												</span>--%>
<%--												<span class="ticket_money">--%>
<%--													<span>¥</span>258/人--%>
<%--												</span>--%>
<%--												--%>
<%--											</td>--%>
<%--										</tr>--%>
<%--									</tbody>--%>
<%--								</table>--%>
<%--							</li>--%>
<%--							--%>
<%--						</div>--%>
<%--						<!-- <a style="color:#1fbad6" href="https://www.tiaonali.com/tnl-member/wechat/trend/candidate/member.page">如何成为会员？→</a> -->--%>
<%--					</div>--%>
					
				<div class="ui segment" >
				<div class="fluid ui button" onclick="signUp()" >我要报名并支付 </div>
			</div>
		</section>
	</div>
	<script src="${ctx}/resources/semanticui/jquery-2.1.4.min.js"></script>
	<script src="${ctx}/resources/trend/semantic/dist/semantic.min.js"	type="text/javascript"></script>
	<script src="${ctx}/resources/trend/semantic/dist/components/modal.min.js"	type="text/javascript"></script>
 	<script src="https://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script> 
	<script type="text/javascript">
		wx.config({
			debug : false,
			appId : "${config.appid}",
			timestamp : ${config.currenttimestamp},
			nonceStr : "${config.nonceStr}",
			signature : "${config.signatureStr}",
			jsApiList : [
			    'checkJsApi',
	 	        'onMenuShareTimeline',
		        'onMenuShareAppMessage',
		        'onMenuShareQQ',
		        'onMenuShareWeibo',
		        'showOptionMenu',
		        'chooseWXPay' 
		    ]
		});
		
		var totalFee = 0;
		var selectCode = null;
		//在该函数中,执行wxpay之前要算出最终金额和码
		function signUp(){
			/* var codeType = $(".code_tab label.active").data("type");
			if(isNull(codeType)){
				alert("推荐码类型为空");
				return;
			}
			if ("vipCode"==codeType) {
				selectCode = $("input[name='vipCode']").val();
				console.log("selectCode"+selectCode);
				//验证通过后，在该函数里ajax的回调处调用wxpay
				validVipCode(selectCode);
				totalFee = 0;
			} */
			//else if("recomCode"==codeType){
				var money = $(".ticket.select").data("money");
				if(isNull(money)){
					alert("请选择票种");
					return;
				}else{
					//selectCode = $("input[name='recomCode']").val();
					totalFee = money
					wxpay();
				}
				
			//}
			/* else{
				alert("推荐码类型错误");
				return;
			} */
		}

		function isNull(obj){
			if(obj==null||obj==undefined||obj.length<1){
				return true;
			}
			return false;
		}
		
		function wxpay() {
			var openid = $("#openid").val();
			var companyname = $("#companyname").val();
			var positionname = $("#positionname").val();
			var name = $("#name").val();
			var phone = $("#phone").val();
			var bodydesc=$("#bodydesc").val();
			var payType=$("#payType").val();
			var goodsid=$("#goodsid").val();
			if (!name || name == "") {
				alert("您必须输入姓名");
				return false;
			}
			if (name.length > 40) {
				alert("名字太长");
				return false;
			}
			if (!/^[0-9]+$/.test(phone) || phone <= 0) {
				alert("您必须输入电话");
				return false;
			}
			if (!companyname || companyname == "") {
				alert("您必须输入公司名称");
				return false;
			} 
			if (!positionname || positionname == "") {
				alert("您必须输入您目前担任的职位");
				return false;
			} 
			
			if (isNull(totalFee)||totalFee<0) {
				alert("请选择需要报名费用");
				return false;
			}
			
			//测试时修改为自己的openId 如果不修改会出现【下单账号与支付账号不一致】的提示 这里最好授权获取
			var tmpname= name+"-"+companyname+"-"+positionname;
			console.log(totalFee);
			if(totalFee==0){
				$.post("https://www.tiaonali.com/tnl-wxapp/user/saveMemberOrder",{
					"openid":openid,"phone":phone,"name":tmpname,"bodydesc":bodydesc,"goodsid":goodsid,"type":payType},
						function(data){
							if("200"==data.code){
								//验证通过
								location.href = "${ctx}/wechat/trend/candidate/endetail.page";
							}else{
								//验证不通过
								alert("报名失败，详情联系Lin：18721386781");
							}
						},'json');
			}else{
				$.post("${ctx}/wechat/trend/candidate/enpay.page", {
					total_fee : totalFee,
					name : tmpname,
					phone:phone,
					bodydesc:bodydesc,
					type:payType,
					goodsid:goodsid
				}, function(res) {
					if (res.code == 0) {
						var data = JSON.parse(res.data);
						//JSSDK支付所需的配置参数，首先会检查signature是否合法。
						if (typeof WeixinJSBridge == "undefined") {
							if (document.addEventListener) {
								document.addEventListener('WeixinJSBridgeReady',
										onBridgeReady(data), false);
							} else if (document.attachEvent) {
								document.attachEvent('WeixinJSBridgeReady',
										onBridgeReady(data));
								document.attachEvent('onWeixinJSBridgeReady',
										onBridgeReady(data));
							}
						} else {
							onBridgeReady(data);
						}
					} else {
						if (res.code == 2) {
							alert(res.message);
						} else {
							alert("参数错误：" + res.message);
						}
					}
				});
			}


		}

		function onBridgeReady(data) {
			console.log("appId=" + data.appId);
			console.log("timeStamp=" + data.timeStamp);
			console.log("nonceStr=" + data.nonceStr);
			console.log("package=" + data.package);
			console.log("paySign=" + data.paySign);
			WeixinJSBridge.invoke('getBrandWCPayRequest',
			{
				"appId" : data.appId,
				"timeStamp" : data.timeStamp,
				"nonceStr" : data.nonceStr,
				"package" : data.package,
				"signType" : 'MD5',
				"paySign" : data.paySign
			},
			function(res) { // 使用以上方式判断前端返回,微信团队郑重提示：res.err_msg将在用户支付成功后返回  ok，但并不保证它绝对可靠。  
				//$("#actionResult").text(JSON.stringify(res));
				if (res.err_msg == "get_brand_wcpay_request:ok") {
					location.href = "${ctx}/wechat/trend/candidate/endetail.page";
				}
				if (res.err_msg == "get_brand_wcpay_request:cancel") {
				}
				if (res.err_msg == "get_brand_wcpay_request:fail") {
					alert("支付失败");
				}
			});
		}
		
		 $(document).ready(function() { 
		      wx.ready(function(){ 
		          wx.onMenuShareAppMessage({
		              title: '医趋势会员全新升级',
		              desc: '全新的升级，全面的服务',
		              link: 'http://www.tiaonali.com${ctx}/register/enlist.page',
		              imgUrl:'https://headoffer.com/logo_v2.png',
		              type: 'link'
		          });
		  
		          wx.onMenuShareTimeline({
		              title: '医趋势会员全新升级',
		              desc: '全新的升级，全面的服务',
		              link: 'http://www.tiaonali.com${ctx}/register/enlist.page',
		              imgUrl:'https://headoffer.com/logo_v2.png'
		          });

		          wx.showOptionMenu();
		      });
		      
		    /*   $(".code_tab label").click(function(){
			    	$(".code_tab label").removeClass("active");
			    	$(this).addClass("active");
			    	var type = $(this).data("type");
			    	if("vipCode"==type){
			    		$(".ticket_con").hide();
			    	}else{
			    		$(".ticket_con").show();
			    	}
			    	var cls = "."+type;
			    	$(".code_con").hide();
			    	$(cls).show();
			    }); */
		     /*  $("input[name='code']").bind("input propertychange",function(event){
		    	  	console.log("输入了推荐码"+$(this).val());
					validRecomCode($(this).val());
				}); */
			 var isMember=false;
			 <c:if test="${employee!=null}">
			 	 console.log("employee STEP=1 是会员");
				isMember=true;
			 </c:if>
		      $(".ticket").click(function(){
		    	  console.log("isMember="+isMember);
		    	  if(!isMember){
		    		  //不是会员不可以选票
		    		  return;
		    	  } 
		    	  $(".ticket").removeClass("select");
		    	  $(this).addClass("select");
		      });
		       
		    });
		 
		//验证vip码
		function validVipCode(code){
			if(code==null||code.length<1){
				alert("请输入vip码");
				return;
			}
			$.post("https://www.tiaonali.com/tnl-wxapp/form/selectFormId",{"formid":code,"type":1},
				function(data){
					if("200"==data.code){
						//验证通过
						wxpay();
					}else{
						//验证不通过
						alert("vip码错误");
					}
				},'json');
		}

		//验证推荐码
		function validRecomCode(code){
			if(code==null||code.length<1){
				//为空则不验证
				return;
			}
			$.post("https://www.tiaonali.com/tnl-wxapp/form/selectFormId",{"formid":code,"type":0},
				function(data){
					if("200"==data.code){
						//验证通过
						$(".ticket[data-money='1000']").hide();
						$(".ticket").removeClass("select");
						$(".ticket[data-money='800']").addClass("select");
					}else{
						//验证不通过
						$(".ticket[data-money='1000']").show();
						$(".ticket").removeClass("select");
						$(".ticket[data-money='1000']").addClass("select");
					}
				},'json');
		}
		
	</script>
</body>
</html>